/// <reference path="../../../../../../typings/angularjs/angular.d.ts"/>
define(['./../initial', './../model/Project', './../model/PublicMap', './../controller/project/projectsCtrl', './../controller/project/projects.detail.locationCtrl', './../controller/project/projects.detail.statusCtrl', './../controller/project/projects.detail.summaryCtrl', './../controller/project/projects.detail.typesCtrl', './../controller/project/projects.detail.pointsCtrl', './../controller/project/projects.detail.mileageCtrl', './../controller/project/projects.detail.bindingsCtrl', './../controller/project/projects.detail.propertiesCtrl', './../controller/project/projects.detail.layersCtrl', './../controller/project/projects.detail.deleteCtrl', './../controller/project/projects.detail.prjDeleteCtrl', './../controller/project/projects.addnewCtrl', './../model/Corporation', './../service/showInfoModal', './../service/showMsg'], function () {
    var app = angular.module('App.home');
    app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
        function ($stateProvider, $urlRouterProvider, $locationProvider) {

            // Now set up the states
            $urlRouterProvider.when('/projects/{prjId:[0-9]+}', ['$stateParams', '$state', function ($stateParams, $state) {
                $state.go('projects.detail.location', {
                    prjId: $stateParams.prjId
                });
            }]);

            $stateProvider
                .state('projects', {
                    resolve: {
                        //提前获取权限项目
                        Project: "Project",
                        allProjects: ["Project", function (Project) {
                            return Project.getAllCityList();
                        }]
                    },
                    url: "/projects",
                    templateUrl: "/partials/project/projects",
                    controller: 'projectsCtrl'
                })
                .state('projects.detail', {
                    url: "/{prjId:[0-9]+}",
                    // abstract: true,
                    resolve: {
                        //controller的所有依赖注入需要在resolve里定义,跟之前的AMD加载有所区别
                        showMsg: 'showMsg', //提示框
                        //根据prjId,查找到curPrj
                        curPrj: ['$stateParams', '$state', 'Project', '$rootScope', 'allProjects',
                            function ($stateParams, $state, Project, $rootScope, allProjects) {
                                var curPrj = Project.getCurProject($stateParams.prjId);
                                if (curPrj === null) {
                                    $state.go('projects');
                                } else {
                                    return curPrj;
                                }
                            }
                        ]
                    },
                    templateUrl: '/partials/project/projects/detail'
                })
                .state('projects.detail.location', {
                    url: "/location",
                    resolve: {
                        PublicMap: 'PublicMap'
                    },
                    templateUrl: '/partials/project/projects/detail/location',
                    controllerProvider: function () {
                        return 'projects.detail.locationCtrl';
                    }
                })
                .state('projects.detail.status', {
                    url: "/status",
                    resolve: {
                        PrjStatus: 'PrjStatus',
                        showInfoModal: 'showInfoModal',
                        prjStatusList: ['curPrj', function (curPrj) {
                            return curPrj.getStatusList();
                        }]
                    },
                    templateUrl: '/partials/project/projects/detail/status',
                    controller: 'projects.detail.statusCtrl'
                })
                .state('projects.detail.summary', {
                    url: "/summary",
                    templateUrl: '/partials/project/projects/detail/summary',
                    controller: 'projects.detail.summaryCtrl'
                })
                .state('projects.detail.types', {
                    url: "/types",
                    resolve: {
                        Project: 'Project'
                    },
                    templateUrl: '/partials/project/projects/detail/types',
                    controller: 'projects.detail.typesCtrl'
                })
                .state('projects.detail.points', {
                    url: "/points",
                    templateUrl: '/partials/project/projects/detail/points',
                    controller: 'projects.detail.pointsCtrl'
                })
                .state('projects.detail.mileage', {
                    url: "/mileage",
                    templateUrl: '/partials/project/projects/detail/mileage',
                    controller: 'projects.detail.mileageCtrl'
                })
                .state('projects.detail.bindings', {
                    url: "/bindings",
                    templateUrl: '/partials/project/projects/detail/bindings',
                    controller: 'projects.detail.bindingsCtrl'
                })
                .state('projects.detail.properties', {
                    url: "/properties",
                    resolve: {
                        corporationList: ['Corporation', function (Corporation) {
                            return Corporation.getCorporationList();
                        }]
                    },
                    templateUrl: '/partials/project/projects/detail/properties',
                    controller: 'projects.detail.propertiesCtrl'
                })
                .state('projects.detail.layers', {
                    url: '/layers',
                    resolve: {
                        Project: 'Project'
                    },
                    templateUrl: '/partials/project/projects/detail/layers',
                    controller: 'projects.detail.layersCtrl'
                })
                .state('projects.detail.delete', {
                    url: '/delete',
                    resolve: {
                        showInfoModal: 'showInfoModal',
                        showMsg: 'showMsg'
                    },
                    templateUrl: '/partials/project/projects/detail/delete',
                    controller: 'projects.detail.deleteCtrl'
                })
                .state('projects.detail.prjDelete', {
                    url: '/deleteProject',
                    resolve: {
                        showInfoModal: 'showInfoModal',
                        showMsg: 'showMsg',
                        Project: 'Project'
                    },
                    templateUrl: '/partials/project/projects/detail/deleteProject',
                    controller: 'projects.detail.prjDeleteCtrl'
                })
                .state('projects.addnew', {
                    url: "/addnew",
                    resolve: {
                        Project: 'Project',
                        corporationList: ['Corporation', function (Corporation) {
                            return Corporation.getCorporationList();
                        }],
                        showMsg: 'showMsg' //提示框
                    },
                    templateUrl: '/partials/project/projects/addnew',
                    controller: 'projects.addnewCtrl'
                });
        }
    ]);



});
